﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MinhTam.DataAccess.Web;
using MinhTam.Objects;

public partial class lienhe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            noidung.config.toolbar = new object[]{
                new object[]{"Bold","Italic", "Underline","Strike","Subscript","Superscript", "-","RemoveFormat" },
              new object[]{  "NumberedList" ,"BulletedList","-" ,"Outdent" ,"Indent" ,	"- ","JustifyLeft" ,"JJustifyCenter", "JustifyRight", "JustifyBlock"  } ,
            };
            noidung.config.uiColor = HelpUtil.GetCKEditorUiColorUser(this);
            InitLienHe();
        }
    }
    private void InitLienHe()
    {
        try
        {
            string sql = "select top 1 TEN_VAN_PHONG,DIA_CHI,DIEN_THOAI,FAX,HOT_LINE,EMAIL from van_phong where is_lien_he='Y'";
            DataTable dt = SQLConnectWeb.GetTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow r = dt.Rows[0];
                lblCompany.InnerText = r[VAN_PHONG.cl_TEN_VAN_PHONG].ToString().ToUpper();
                lblDiaChi.InnerHtml = "<br/> Địa chỉ: " + r[VAN_PHONG.cl_DIA_CHI];
                lblDienThoai.InnerHtml = "<br/>Điện thoại: " + r[VAN_PHONG.cl_DIEN_THOAI];
                if (r[VAN_PHONG.cl_HOT_LINE].ToString() != "")
                    lblHotLine.InnerHtml = "<br/>Hot line: " + r[VAN_PHONG.cl_HOT_LINE];
                if (r[VAN_PHONG.cl_FAX].ToString() != "")
                    lblFax.InnerHtml = "<br/>Fax: " + r[VAN_PHONG.cl_FAX];
                if (r[VAN_PHONG.cl_EMAIl].ToString() != "")
                    lblEmail.InnerHtml = (lblFax.InnerText == "" ? "<br/>" : "") + "Email: " + r[VAN_PHONG.cl_EMAIl];
            }
        }
        catch
        {
        }
    }
    protected void btnluu_Click(object sender, EventArgs e)
    {
        try
        {
            //Luu thong tin lien he
        

            string sql = @"INSERT INTO BAI_VIET(TEN_BAI_VIET,NOI_DUNG,	LOAI_BAI_VIET,	NGUOI_TAO_NAME,NGAY_TAO,NGUOI_TAO_EMAIL,NGUOI_TAO_SDT,NGUOI_TAO_DIA_CHI) 
                        VALUES( @TEN_BAI_VIET,	@NOI_DUNG,	@LOAI_BAI_VIET, @NGUOI_TAO_NAME,	getdate(),@NGUOI_TAO_EMAIL,@NGUOI_TAO_SDT,@NGUOI_TAO_DIA_CHI)";


            bool ok = SQLConnectWeb.ExecuteNonQuery(sql,
                     "@TEN_BAI_VIET", tieude.Text,
                     "@NOI_DUNG", noidung.Text.Replace("'", ""),
                     "@LOAI_BAI_VIET", HelpConstEnum.LoaiBaiViet.Y_KIEN_KHACH_HANG.GetHashCode().ToString(),
                     "@NGUOI_TAO_NAME", hovaten.Text,
                    "@NGUOI_TAO_EMAIL", email.Text,
                    "@NGUOI_TAO_SDT", sodt.Text,
                    "@NGUOI_TAO_DIA_CHI", diachi.Text
                   ) > 0;

            if (ok)
            {
                Response.Redirect("default.aspx");
            }
           
        }
        catch
        {
        }
    }
}